/**
 * Created by shitao on 15/10/13.
 */
(function () {
    angular.module('my-tabs')
        .config(commonConfig);

    commonConfig.$inject = ['$ionicConfigProvider', 'amTimeAgoConfig', '$httpProvider'];

    function commonConfig($ionicConfigProvider, amTimeAgoConfig, $httpProvider) {
        $httpProvider.defaults.headers.post = {'Content-Type': 'application/json;charset=utf-8'};
        $httpProvider.defaults.headers.put = {'Content-Type': 'application/json;charset=utf-8'};
        $httpProvider.defaults.headers.delete = {'Content-Type': 'application/json;charset=utf-8'};
        $httpProvider.defaults.cache = false; // 默认关闭缓存？

        amTimeAgoConfig.fullDateThreshold = 2;
        amTimeAgoConfig.fullDateFormat = 'MM月DD日';

        $ionicConfigProvider.navBar.alignTitle('center');
        $ionicConfigProvider.tabs.style('standard').position('bottom');
        //$ionicConfigProvider.views.forwardCache(true);
        //when title is too long
        $ionicConfigProvider.backButton.text('返回').icon('ion-ios7-arrow-left').previousTitleText(false);

        $httpProvider.interceptors.push('httpInterceptor');
    }
})();

/**
 * Created by shitao on 15/10/13.
 */
(function () {
    angular.module('my-tabs')
        .config(routesConfig);
    routesConfig.$inject = ['$stateProvider', '$urlRouterProvider'];

    function routesConfig($stateProvider, $urlRouterProvider) {

        $stateProvider
            // 抽象父状态，用来设置Tabs
            .state('main', {
                url: '/main',
                abstract: true,
                templateUrl: 'views/main.html',
                controller: 'mainCtrl as vm'
            })
            // "首页"页面
            .state('main.home', {
                url: '/home',
                views: {
                    'main-home': {
                        templateUrl: 'views/home.html',
                        controller: 'homeCtrl as vm'
                    }
                }
            })
            // "资讯"页面
            .state('main.news', {
                url: '/news',
                views: {
                    'main-news': {
                        templateUrl: 'views/news/list.html',
                        controller: 'newsCtrl as vm'
                    }
                }
            })
            // "资讯明细"页面
            .state('main.news-detail', {
                url: '/news/:id',
                views: {
                    'main-approvals': {
                        templateUrl: 'views/news/detail.html',
                        controller: 'newsDetailCtrl as vm'
                    }
                }
            })
            // "发现"页面
            .state('main.explore', {
                url: '/explore',
                views: {
                    'main-explore': {
                        templateUrl: 'views/explore.html',
                        controller: 'exploreCtrl as vm'
                    }
                }
            })
            // "我的"页面
            .state('main.me', {
                url: '/me',
                views: {
                    'main-me': {
                        templateUrl: 'views/me/index.html',
                        controller: 'meCtrl as vm'
                    }
                }
            })

        // 默认进入“首页”标签页面
        $urlRouterProvider.otherwise('/main/home');

    };
})();
